package com.wedata.致远接口;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

public class 职务管理 {

    public static void main(String[] args) {
        createLevel();
        orgLevels();
    }

    /**
     * 1.4.3. 获取指定单位的所有职务级别(不包含停用)
     * @return
     */
    private static String orgLevels(){
        //accountId	是	单位ID
        //  "orgAccountId" : 670869647114347,
        JSONArray levels = HttpUtils.getList(token.hostUrl + "/rest/orgLevels/all/670869647114347?token="+token.getToken());
        System.out.println(levels.size());
        for(int i=0;i<levels.size();i++){
            JSONObject level = levels.getJSONObject(i);
            System.out.println(level);
        }
        /*
        {"orgAccountId":670869647114347,"id":-6814540232295297094,"name":"系统管理员","code":"","createTime":1678414653977,"updateTime":1686025840053,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"levelId":1,"valid":true,"entityType":"Level","i18nNameWithLocale":"系统管理员","dataI18nCategoryName":"organization.level.name","fullName":"系统管理员","realSortId":0,"preName":""}
        {"orgAccountId":670869647114347,"id":-6086847796728934525,"name":"高管","code":"","createTime":1686013974523,"updateTime":1690437804253,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"levelId":1,"valid":true,"entityType":"Level","i18nNameWithLocale":"高管","dataI18nCategoryName":"organization.level.name","fullName":"高管","realSortId":0,"preName":""}
        {"orgAccountId":670869647114347,"id":-3581886347206246285,"name":"基层人员","code":"","createTime":1686014033883,"updateTime":1690439666173,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"levelId":1,"valid":true,"entityType":"Level","i18nNameWithLocale":"基层人员","dataI18nCategoryName":"organization.level.name","fullName":"基层人员","realSortId":0,"preName":""}
        {"orgAccountId":670869647114347,"id":-53080824737281993,"name":"一般管理人员","code":"","createTime":1686014047627,"updateTime":1690439671930,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"levelId":1,"valid":true,"entityType":"Level","i18nNameWithLocale":"一般管理人员","dataI18nCategoryName":"organization.level.name","fullName":"一般管理人员","realSortId":0,"preName":""}
        {"orgAccountId":670869647114347,"id":1996156927390601086,"name":"中管","code":"","createTime":1686014070957,"updateTime":1690439659340,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"","customerProperties":[],"levelId":1,"valid":true,"entityType":"Level","i18nNameWithLocale":"中管","dataI18nCategoryName":"organization.level.name","fullName":"中管","realSortId":0,"preName":""}
*/
        return "";

    }
    /**
     * 1.4.5. 创建职务级别
     */
    private static String createLevel(){
        JSONObject header  = new JSONObject();
        header.set("token",token.getToken());
        JSONObject body = new JSONObject();
        body.set("orgAccountId","670869647114347");
        body.set("name","研发修改");
        body.set("code","1");
        body.set("description","我是研发接口测试创建的");
        body.set("levelId",1);
        body.set("sortId",0);
        JSONObject result = HttpUtils.sendPost(token.hostUrl + "/rest/orgLevel",header,body);
        //{"successMsgs":[{"code":"SUCCESS","ent":{"orgAccountId":670869647114347,"id":-28350203931242582,"name":"研发测试","i18nNameId":null,"code":"1","createTime":1710812729421,"updateTime":1710812729421,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"我是研发接口测试创建的","customerProperties":[],"levelId":1,"groupLevelId":null,"valid":true,"entityType":"Level","fullName":"研发测试","preName":"","realSortId":0,"i18nNameWithLocale":"研发测试","dataI18nCategoryName":"organization.level.name"},"msgInfo":null}],"errorMsgs":[],"errorMsgInfos":[],"success":true}
        //{"successMsgs":[],"errorMsgs":[{"code":"LEVEL_REPEAT_NAME","ent":{"orgAccountId":670869647114347,"id":-5174869182595380159,"name":"研发修改","i18nNameId":null,"code":"1","createTime":1712046932011,"updateTime":1712046932011,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"我是研发接口测试创建的","customerProperties":[],"levelId":1,"groupLevelId":null,"valid":true,"entityType":"Level","fullName":"研发修改","dataI18nCategoryName":"organization.level.name","i18nNameWithLocale":"研发修改","realSortId":0,"preName":""},"msgInfo":null}],"errorMsgInfos":[{"code":null,"ent":{"orgAccountId":670869647114347,"id":-5174869182595380159,"name":"研发修改","i18nNameId":null,"code":"1","createTime":1712046932011,"updateTime":1712046932011,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"我是研发接口测试创建的","customerProperties":[],"levelId":1,"groupLevelId":null,"valid":true,"entityType":"Level","fullName":"研发修改","dataI18nCategoryName":"organization.level.name","i18nNameWithLocale":"研发修改","realSortId":0,"preName":""},"msgInfo":"已存在相同名称的职务级别，操作失败！"}],"success":false}
        System.out.println(result);
        return "";

    }
    private static String upddateLevel(){
        JSONObject header  = new JSONObject();
        header.set("token",token.getToken());
        JSONObject body = new JSONObject();
        JSONObject field = new JSONObject("{\"field\":\"code\"}");
        body.set("id",field);
        body.set("code","1");
        body.set("description","我是研发接口测试修改的");
        body.set("name","研发修改");
        JSONObject result = HttpUtils.sendPut(token.hostUrl + "/rest/orgLevel",header,body);
        //{"successMsgs":[{"code":"SUCCESS","ent":{"orgAccountId":670869647114347,"id":-28350203931242582,"name":"研发修改","i18nNameId":null,"code":"1","createTime":1710812729420,"updateTime":1710812729420,"sortId":0,"isDeleted":false,"enabled":true,"externalType":0,"status":1,"description":"我是研发接口测试修改的","customerProperties":[],"levelId":1,"groupLevelId":null,"valid":true,"entityType":"Level","fullName":"研发修改","preName":"","realSortId":0,"i18nNameWithLocale":"研发修改","dataI18nCategoryName":"organization.level.name"},"msgInfo":null}],"errorMsgs":[],"errorMsgInfos":[],"success":true}
        System.out.println(result);
        return "";

    }

}
